<?php

namespace app\listener\notify;


use app\event\SupplierNotifyFail;
use app\listener\base\CouponOrderUnion;
use app\model\CouponOrder;


/**
 * 供应商回调失败 统一在这处理  ps:其他的业务逻辑不要在这里写，可单独起个事件监听
 * 更改失败
 */
class CouponOrderUnionFail
{
    /**
     * 事件监听处理
     * @param SupplierNotifyFail $event
     * @return mixed
     */
    public function handle($event)
    {
        $couponOrder = $event->couponOrder;

        if ($couponOrder->serv_type == PRODUCT_COUPON_SERV) {
            return true;
        }

        // 小类型配置
        if ($couponOrder->type != CouponOrder::TYPE_COUPON_SELF_EMPLOYED) {
            return true;
        }

        if ($couponOrder->status == CouponOrder::C_STATUS_RECHARGE_FAIL) {
            return true;
        }

        $couponOrder->status = CouponOrder::C_STATUS_RECHARGE_FAIL;
        $couponOrder->supplier_status = CouponOrder::SUPPLIER_STATUS_FAIL;

        $couponOrder->save();
    }


}